package main

import "fmt"

//节点类型
type ListNode struct {
	date int
	next *ListNode
}

type  LinkList struct {
	Head * ListNode
}

//创建单链表
func (l *LinkList) AddNode(date int){
	newnode :=&ListNode{date,nil}
	if l.Head == nil{
		l.Head =newnode
	}else {
		current := l.Head
		for current.next != nil{
			current =current.next
		}
		current.next =newnode
	}

}

func (l *LinkList) reverse() {
	var prev *ListNode
	current := l.Head
	for current != nil {
		next := current.next
		current.next = prev
		prev = current
		current = next
	}
	l.Head = prev
}

func (l *LinkList) printList(){
	current :=l.Head
	for current != nil{
		fmt.Printf("%d ",current.date)
		current = current.next
	}
	fmt.Println()
}

func main()  {
	lst := LinkList{}
	lst.AddNode(1)
	lst.AddNode(2)
	lst.AddNode(3)


	lst.printList()
	lst.reverse()
	lst.printList()


}